<?php
/**
 * Created by PhpStorm.
 * User: Raytine
 * Date: 2019/11/21
 * Time: 21:58
 */

namespace App\Repository;


use App\Interfaces\MsgInterFace;
use App\Interfaces\MapInterFace;
use App\model\agent\Agent;
use App\model\UserWorkshop;
use App\model\Workshop;
use App\model\WorkshopFabu;
use App\Service\BaiduMapService;
use App\Service\MiniProgramService;
use Illuminate\Database\Query\Builder;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use phpDocumentor\Reflection\DocBlock\Tag;
use Geohash\GeoHash;

class MsgRepository implements MsgInterFace
{
    protected $baiduMapService;
    protected $miniProgramService;
    public function __construct(MapInterFace $baiduMapService,MiniProgramService $miniProgramService)
    {
        $this->baiduMapService = $baiduMapService;
        $this->miniProgramService=$miniProgramService;
    }
    public function  MonthRanking($request)
    {
        $all_rank = DB::select('select * from (SELECT (@i:=@i+1)"oid" ,workorder.* from (select COUNT(*) cou,user_id from workshop GROUP BY user_id ORDER BY cou desc)workorder,(select @i:=0)t
            ) abc where user_id=?', [600]);
        $dian_rank = DB::select('select * from (SELECT (@i:=@i+1)"oid" ,workorder.* from (SELECT * from (select COUNT(*) cou,user_id from workshop GROUP BY user_id ORDER BY cou desc)workorder where user_id in(select user_id from user_department_id where department_id=(select department_id from user_department_id where user_id=600) )
            )workorder,(select @i:=0)t) abc where user_id=?', [600]);
        $qu_rank = DB::select('select * from (SELECT (@i:=@i+1)"oid" ,workorder.* from (SELECT * from (select COUNT(*) cou,user_id from workshop GROUP BY user_id ORDER BY cou desc)workorder where user_id in(select user_id from user_department_id where department_id=(select department_id from user_department_id where user_id=600) )
            )workorder,(select @i:=0)t) abc where user_id=?', [600]);
        $ranking = DB::select('select pai.*,u.name FROM(
            select * from (SELECT (@i:=@i+1)"oid" ,workorder.* from (select COUNT(*) cou,user_id from workshop GROUP BY user_id ORDER BY cou desc)workorder,(select @i:=0)t
            ) abc )pai LEFT JOIN  users u  on u.id=pai.user_id LIMIT 10');
        return response()->json([
            'all_rank' => $all_rank,
            'dian_rank' => $dian_rank,
            'qu_rank' => $qu_rank,
            'ranking' => $ranking
        ]);
    }
}